package com.product.android.commonInterface.contact;

import java.io.Serializable;

import org.json.JSONObject;

import com.common.android.utils.JSONUtils;
import com.product.android.business.ApplicationVariable;

public class OapGroupRelation implements Serializable {
	
	private long uid;
	private long fid;
	private long gid;
	private long updatetime;
	private String nickname;
	private int sex;
	private int grade;
	private int type;
	public static final int GROUPMEMBER = 0;
	public static final int DEPARTMEMBER = 1;
	public static final int CLASSMEMBER = 2;
	public static final int TEACHMEMBER = 3;
	public int classid;
	
	@Override
	public boolean equals(Object o) {
		if(o instanceof OapGroupRelation){
			OapGroupRelation ogr = (OapGroupRelation)o;
			if(ogr.getUid() ==this.getUid()
					&&ogr.getFid() == this.getFid()
					&&ogr.getClassid()== this.getClassid()
					&&ogr.getGid() == this.getGid()
					&&ogr.getType()== this.getType())
				 return true;
		}
		return false;
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	public void initValueByJSON(JSONObject json,long gid){
		if(json==null) return ;
		this.fid = JSONUtils.getLong(json, "uid");
		this.grade = JSONUtils.getInt(json, "grade");
		this.nickname = JSONUtils.getString(json, "nick");
		this.sex = JSONUtils.getInt(json, "sex");
		this.gid = gid;
		this.uid = ApplicationVariable.INSTANCE.getIUser().getBindUser().getUid();
	}
	
	public void initDiscussionByJSON(JSONObject json,long gid){
		if(json==null) return ;
		this.fid = JSONUtils.getLong(json, "uid");
		this.nickname = JSONUtils.getString(json, "username");
		this.gid = gid;
		this.uid = ApplicationVariable.INSTANCE.getIUser().getBindUser().getUid();
	}
		
	public long getGid() {
		return gid;
	}
	
	public long getUpdatetime() {
		return updatetime;
	}
	
	public long getUid() {
		return uid;
	}
	
	public long getFid() {
		return fid;
	}
	
	public void setUid(long uid) {
		this.uid = uid;
	}
	
	public void setFid(long fid) {
		this.fid = fid;
	}
	
	public void setGid(long gid) {
		this.gid = gid;
	}
	
	public void setUpdatetime(long updatetime) {
		this.updatetime = updatetime;
	}
	
	public String getNickname() {
		if(nickname!=null&&!"".equals(nickname)){
			return nickname;
		}else{
			if(fid==ApplicationVariable.INSTANCE.getIUser().getBindUser().getUid()) {
//				return GlobalVariable.getInstance().getCurrentUserName();
				return ApplicationVariable.INSTANCE.getIUser().getBindUser().getNickname();
			}

			//dyf temp
//			OapUser user = UserCacheManager.getInstance().getUser(fid);
//			if(user!=null) return user.getUserName();
			
			else return ""+fid;
		}
	}
	
	public int getGrade() {
		return grade;
	}
	
	public int getSex() {
		return sex;
	}
	
	public void setNickname(String nickname) {
		this.nickname = nickname;
	}
	
	public void setGrade(int grade) {
		this.grade = grade;
	}
	
	public void setSex(int sex) {
		this.sex = sex;
	}

	public int getClassid() {
		return classid;
	}

	public void setClassid(int classid) {
		this.classid = classid;
	}
}